package com.cosina.game.crystallight.model.battle;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import com.cosina.game.crystallight.model.profile.ProfileManager;

/***
 * 		     39
 * 		   37  38 
 * 		34   35  36
 * 		   32  33
 * 		29   30  31   
 * 		   27  28
 * 		24   25  26
 * 		  22  23
 *      19   20  21
 * 		  17  18
 *      14  15  16      
 *            13
 *      10  11  12
 *        8   9
 *      5   6   7
 *		  3   4
 *		1   0   2
 */
public class BattleFieldProxyManager {
	
	public String getOveredPersistString(){
		String temp = Arrays.toString(overedTollGates.toArray(new String[0]));
		return temp.substring(1,temp.length()-1);
	}
	
	public List<String> overedTollGates = new ArrayList<String>();
	public Set<String> cangoTollGates = new TreeSet<String>();
	private static Map<String,BattleFieldProxy> ALLTOLLGATE = new HashMap<String,BattleFieldProxy>();
	
	public static BattleFieldProxy get(int id){
		return ALLTOLLGATE.get(id + "");
	}
	
	public static BattleFieldProxy get(String id){
		return ALLTOLLGATE.get(id.trim());
	}
	
	public BattleFieldProxyManager(String[] overedTollGatesIds){
		
		for(String each : overedTollGatesIds){
			overedTollGates.add(each);
		}

		refreshCango();
	}
	
	private void refreshCango(){
		cangoTollGates.clear();
		for(String each : ALLTOLLGATE.keySet()){
			if(overedTollGates.contains(each))
				continue;
			int[] requiredGates = ALLTOLLGATE.get(each).requireds;
			boolean requiredIsOk = true;
			for(int i=0; i<requiredGates.length; i++){
				if(overedTollGates.contains(requiredGates[i] + "") == false){
					requiredIsOk = false;
				}
			}
			if(requiredIsOk){
				cangoTollGates.add(each);
			}
		}
	}
	
	public void newOvered(String id){
		for(String each : overedTollGates){
			if(each.equals(id)){
				return;
			}
		}
		overedTollGates.add(id);
		refreshCango();
		ProfileManager.getCurrentProfile().skillManager.add();
	}
	

	/***
	 * 		     39
	 * 		   37  38 
	 * 		34   35  36
	 * 		   32  33
	 * 		29   30  31   
	 * 		   27  28
	 * 		24   25  26
	 * 		  22  23
	 *      19   20  21
	 * 		  17  18
	 *      14  15  16      
	 *            13
	 *      10  11  12
	 *        8   9
	 *      5   6   7
	 *		  3   4
	 *		1   0   2
	 */
	static{
		addProxy(0,"Chambord",new int[]{},3,
				128,379,0,15000);
		addProxy(1,"Avignon",new int[]{0},3,
				18,370,1,21000);
		addProxy(2,"Foix",new int[]{0},3,
				231,362,0,28000);
		addProxy(3,"Tarascon",new int[]{1},3,
				61,261,1,37000);
		addProxy(4,"Vincennes",new int[]{2},3,
				198,252,0,41000);
//		
		addProxy(5,"Amboise",new int[]{3},3,
				23,148,1,54000);
		addProxy(6,"Elos Luce",new int[]{5,7},3,
				129,140,0,74000);
		addProxy(7,"Chaumont",new int[]{4},3,
				226,147,1,70000);
		addProxy(8,"Falkenstein",new int[]{6},3,
				79,33,0,95000);
		addProxy(9,"Wartburg",new int[]{6},3,
				172,41,1,100000);
//		
//		
		addProxy(10,"Bodiam",new int[]{8},2,
				22,407,0,120000);
		addProxy(11,"Arundel",new int[]{10,12},2,
				129,415,1,160000);
		addProxy(12,"Dover",new int[]{9},2,
				231,406,0,14000);
		
		
		
//		addProxy(13,"Lindisfarne",50,new int[]{11},3,61,261,1,18000);
//		addProxy(14,"Biggleswade",53,new int[]{2},3,198,252,0,19000);
//		
//		addProxy(15,"Conwy",56,new int[]{16},3,128,379,0,260000);
//		addProxy(16,"Harlech",58,new int[]{13},3,19,369,1,260000);
//		addProxy(17,"Pembroke",61,new int[]{14},3,232,361,0,280000);
//		addProxy(18,"Bothwell",64,new int[]{16},3,61,261,1,310000);
//		addProxy(19,"Crathes",66,new int[]{20},3,198,252,0,360000);
	}
	
	private static void addProxy(int id,String name,int[] required,int belongmap, int leftTopx,int leftTopy,int style,int glodenSocre){
		ALLTOLLGATE.put(id + "",new BattleFieldProxy(id,name,required,belongmap,leftTopx,leftTopy,style,glodenSocre));
	}
}
